
var app = sm('do_App');
var page = sm("do_Page");
var service_url = sm("do_Global");
var url  = service_url.getMemory("service_url");
//定义UI组件
var back_btn = ui("do_Button_Cancel");
var do_Button_forward = ui("do_Button_forward");
var mData = page.getData();
var cacher = sm("do_DataCache");
var userInfo = "";
var result = "";
//点击下一步跳转界面
getmember();
do_Button_forward.on("touch", function() {
	
	
	
	pay();
	
	
});

function pay(){
	var http = mm("do_Http");
	http.method = "POST";
	http.timeout = 30000;
	http.contentType = "application/json";
	http.setRequestHeader("X-Requested-With", "XMLHttpRequest");
	var token = cacher.loadData("token");
	http.setRequestHeader("Cookie", token+"");
	http.url = url+"index.php?s=/admin/member/addmemberaccount";
	//s	/admin/member/addmemberaccount
	//http.body = "id="+mData.uid+"&type=2&num="+mData.valueStore;
	http.body = {
			"id":mData.uid,
			"type":"2",
			"num":mData.money*(-1)
	}
	deviceone.print(JSON.stringify(http.body),"http.body ");

	http.on("success", function(data) {
		//nf.toast(data);
		//将数据添加到组件中
		deviceone.print(JSON.stringify(data),"data");
		result ={
				"title":"消费成功",
				"message":"消费成功",
				"money":mData.money,
				"balance":userInfo.balance,
				"moneyvalue":mData.money,
				"moneyType":"无"
		}
		if(data.code==1){
			app.openPage({
				source:"source://view/Consumption/storedvaluedetailsuccess.ui", 
				data:result
				});
		}else{
			nf.toast("操作失败");
		}
		
	});
	http.request();
}

//获取会员详情
function getmember(){
	var http = mm("do_Http");
	http.method = "POST";
	http.timeout = 30000;
	http.contentType = "application/json";
	http.setRequestHeader("X-Requested-With", "XMLHttpRequest");
	var token = cacher.loadData("token");
	http.setRequestHeader("Cookie", token+"");
	http.url = url+"index.php?s=/admin/member/memberlist";
	http.body = "uid="+mData.uid;
//	http.body = {
//			"uid":mData.uid
//	}
	http.on("success", function(data) {
		//nf.toast(data);
		userInfo = data.data[0];
		ui('acount').text = userInfo.user_name;
		ui('name').text = userInfo.nick_name;
		ui('add').text = userInfo.location;
		ui('phone').text = userInfo.user_tel;
		ui('money').text = mData.money;//储值金额
		ui('moneyType').text = "暂无优惠";
		ui('moneyvalue').text = mData.money;
		ui('resmoney').text = userInfo.balance;
	});
	http.request();
}

page.on('loaded',function(){
	getmember();
	
});
page.on('back',function(){
	app.closePage(page);
});

/*****返回按钮*****/
back_btn.on("touch",function(){
	app.closePage(page);
});

